package com.hzit.controller;

import cn.hutool.http.server.HttpServerRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hzit.dto.StudentDTO;
import com.hzit.entity.PageResult;
import com.hzit.entity.R;
import com.hzit.entity.Student;
import com.hzit.service.IStudentService;
import com.hzit.vo.StudentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private IStudentService studentService;

	//1. 查询所有学生
	@GetMapping("/list")
	public R<List<Student>> list(){
		List<Student> students = studentService.findAll();
		return R.ok(students);
	}
	//2. 分页查询
	@GetMapping("/findByPage")
	public R<PageResult<Student>> findByPage(int page,int pageSize){
		PageResult<Student> studentPageResult = studentService.findByPage(page,pageSize);
		return R.ok(studentPageResult);
	}
	//3. 条件查询带分页
	@PostMapping("/search")
	// @RequestBody: 将前端的json转换为java对象
	// @ResponseBody: 将返回的java对象转换为json串
	public R<PageResult<StudentDTO>> search(int page, int pageSize, @RequestBody StudentVo vo){
		System.out.println("vo = " + vo);
		PageResult<StudentDTO> studentPageResult = studentService.search2(page,pageSize,vo);
		return R.ok(studentPageResult);
	}
}
